﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate;
using NHibernate.Criterion;
using Thaire.Investment.Domains.Master;

namespace Thaire.Investment.Repository
{
    public class FundNameRepo : BaseRepository<FundName, int>
    {
        public FundNameRepo(ISession session)
            : base(session)
        {
        }

        public List<FundName> GetFundThNamesByName(string name)
        {
            return new List<FundName>(_session.QueryOver<FundName>()
                .Where(x => x.Lang == "TH")
                .And(Restrictions.Like("Name", name + '%'))
                //.And(x => x.Name.StartsWith(name))
                .OrderBy(x => x.Name).Asc.List());
        }

        public List<FundName> GetFundEnNamesByName(string name)
        {
            return new List<FundName>(_session.QueryOver<FundName>()
                .Where(x => x.Lang == "EN")
                .And(Restrictions.Like("Name", name + '%'))
                //.And(x => x.Name.StartsWith(name))
                .OrderBy(x => x.Name).Asc.List());
        }
        public List<FundName> GetFundNameByNameAndLang(string name, string lang)
        {
            return new List<FundName>(_session.QueryOver<FundName>()
                .Where(x => x.Lang == lang).And(x => x.Name == name).List());
        }
    }

}
